<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>Listen美食城|美味小吃|营养丰富</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="format-detection" content="telephone=no">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="alternate icon" type="image/png" href="/Public/vendor/assets/i/favicon.png">
    <link rel="stylesheet" href="/Public/vendor/assets/css/amazeui.min.css"/>
    <style>
        .header {
            text-align: center;
        }

        .header h1 {
            font-size: 200%;
            color: #333;
            margin-top: 30px;
        }

        .header p {
            font-size: 14px;
        }
    </style>
</head>
<body>
<div class="header">
    <div class="am-g">
        <h1>Listen美食城后台注册页面</h1>
    </div>
    <hr/>
</div>
<div class="am-g">
    <div class="am-u-lg-4 am-u-md-6 am-u-sm-centered">
        <h3>注册</h3>
        <hr>
        <div class="am-btn-group">
            <a href="#" class="am-btn am-btn-secondary am-btn-sm"><i class="am-icon-github am-icon-sm"></i> Github</a>
            <a href="#" class="am-btn am-btn-success am-btn-sm"><i class="am-icon-google-plus-square am-icon-sm"></i>
                Google+</a>
        </div>
        <br>
        <br>

        <form class="am-form">
            <div class="am-input-group">
                <span class="am-input-group-label"><i class="am-icon-user am-icon-fw"></i></span>
                <input type="text" name="username" id="username" class="am-form-field" placeholder="请输入用户名" autofocus>
            </div>
            <br>
            <div class="am-input-group">
                <span class="am-input-group-label"><i class="am-icon-phone am-icon-fw"></i></span>
                <input type="text" name="mobile" id="mobile" class="am-form-field" placeholder="请输入手机号">
            </div>
            <br>
            <div class="am-input-group">
                <span class="am-input-group-label"><i class="am-icon-envelope am-icon-fw"></i></span>
                <input type="text" name="email" id="email" class="am-form-field" placeholder="请输入邮箱">
            </div>
            <br>
            <div class="am-input-group">
                <span class="am-input-group-label"><i class="am-icon-lock am-icon-fw"></i></span>
                <input type="password" name="password" id="password" class="am-form-field" placeholder="请输入密码">
            </div>
            <br>
            <div class="am-input-group">
                <span class="am-input-group-label"><i class="am-icon-lock am-icon-fw"></i></span>
                <input type="password" name="check_password" id="check_password" class="am-form-field"
                       placeholder="请确认密码">
            </div>
            <br/>
            <div class="am-cf">
                <input type="submit" value="注 册" class="submit am-btn am-btn-primary am-btn-sm am-fl">
                <a href="<?php echo U('User/login');?>" class="am-btn am-btn-success am-btn-sm am-fr">请登录 ^_^? </a>
            </div>
        </form>
        <hr>
        <p>© 2014 AllMobilize, Inc. Licensed under MIT license.</p>
    </div>
</div>
<script src="/Public/vendor/assets/js/jquery-3.2.1.min.js"></script>

<script>

    //ajax注册
    $(function () {
        $(".submit").click(function () {
            var info = {
                username: $("#username").val(),
                mobile: $("#mobile").val(),
                email: $("#email").val(),
                password: $("#password").val(),
                check_password: $("#check_password").val()
            };
            //邮箱正则
            var email = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
            //手机号正则
            var mobile = /^13[\d]{9}$|^14[5,7]{1}\d{8}$|^15[^4]{1}\d{8}$|^17[0,6,7,8]{1}\d{8}$|^18[\d]{9}$/;

            if (info.username.length < 5 || info.username.length > 20) {
                alert('用户名的长度必须在5-20位之间');
                return false;
            }
            if (!mobile.test(info.mobile)) {
                alert('手机号格式不正确');
                return false;
            }
            if (!email.test(info.email)) {
                alert('邮箱格式不正确');
                return false;
            }
            if (info.password.length < 6) {
                alert('密码的长度不能小于6位');
                return false;
            }
            if (info.password != info.check_password) {
                alert('两次输入的密码不一致');
                return false;
            }

           $.post("<?php echo U('ajax_register');?>",info,function (info) {
               if(info.status == 1){
                   alert(info.msg);
                   location.href = "<?php echo U('User/login');?>";
               }else{
                   alert(info.msg);
               }
           })
            return false;
        })

    })

</script>

</body>
</html>